package cn.com.cifi.mars.web.action.monitoringConsole;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import cn.com.cifi.mars.bean.dto.MonitorConfigDetailDto;
import cn.com.cifi.mars.bean.vo.monitoringConsole.CoreQuotaVo;
import cn.com.cifi.mars.bean.vo.monitoringConsole.PortalTodoVo;
import cn.com.cifi.mars.bean.vo.monitoringConsole.PriceValueVo;
import cn.com.cifi.mars.bean.vo.monitoringConsole.ProduceItemVo;
import cn.com.cifi.mars.bean.vo.monitoringConsole.ReturnItemVo;
import cn.com.cifi.mars.bean.vo.monitoringConsole.SaleItemVo;
import cn.com.cifi.mars.bean.vo.monitoringConsole.StatementItemVo;
import cn.com.cifi.mars.bean.vo.monitoringConsole.StockItemVo;
import cn.com.cifi.mars.bean.vo.monitoringConsole.StoreItemVo;
import cn.com.cifi.mars.bean.vo.monitoringConsole.StoreSaleRateVo;
import cn.com.cifi.mars.bean.vo.monitoringConsole.SupplyItemVo;
import cn.com.cifi.mars.bean.vo.sys.rsp.UserDataPermissionVo;
import cn.com.cifi.mars.common.base.BaseAction;
import cn.com.cifi.mars.common.bean.R;
import cn.com.cifi.mars.constant.Constants;
import cn.com.cifi.mars.entity.common.IdmUser;
import cn.com.cifi.mars.service.CommonService;
import cn.com.cifi.mars.service.MonitoringConsoleService;
import cn.com.cifi.mars.service.MonitoringUserConsoleService;
import cn.com.cifi.mars.service.PortalTodoTaskService;
import cn.com.cifi.mars.service.SupervisoryConsoleReturnDetailService;

/**
 * 监控台
 * @author Administrator
 *
 */
@RestController
public class MonitoringConsoleController extends BaseAction implements IMonitoringConsoleController {

	@Autowired
	private MonitoringConsoleService monitoringConsoleService;
	@Autowired
	private MonitoringUserConsoleService monitoringUserConsoleService;
	@Autowired
	private CommonService commonService;
	@Autowired
	private PortalTodoTaskService portalTodoTaskService;
	@Autowired
	private SupervisoryConsoleReturnDetailService supervisoryConsoleReturnDetailService;
	
	/**
	 * 货值监控
	 */
	@Override
	public R<PriceValueVo> getValueMonitoring(String apiVersion, String orgId, String reportDate) {
		return ok(monitoringConsoleService.getValueMonitoring(orgId,reportDate));
	}

	/**
	 * 核心指标监控
	 */
	@Override
	public R<CoreQuotaVo> getCoreQuotaStore(String apiVersion, String orgId, String reportDate,String hrOrgTypeId) {
		return ok(monitoringConsoleService.getCoreQuotaStore(orgId,reportDate,hrOrgTypeId));
	}

	/**
	 * 监控指标-储明细
	 */
	@Override
	public R<StoreItemVo> getStoreItem(String apiVersion, String orgId, String reportDate,String hrOrgTypeId) {
		List<MonitorConfigDetailDto> monitorConfigDetailDtoList=monitoringConsoleService.getDetailByOrgId(orgId,hrOrgTypeId); 
		return ok(monitoringConsoleService.getStoreItem(orgId,reportDate,monitorConfigDetailDtoList,hrOrgTypeId));
	}

	/**
	 * 监控指标-产明细
	 */
	@Override
	public R<ProduceItemVo> getProduceItem(String apiVersion, String orgId, String reportDate,String hrOrgTypeId) {
		List<MonitorConfigDetailDto> monitorConfigDetailDtoList=monitoringConsoleService.getDetailByOrgId(orgId,hrOrgTypeId); 
		return ok(monitoringConsoleService.getProduceItem(orgId,reportDate,monitorConfigDetailDtoList,hrOrgTypeId));
	}

	/**
	 * 监控指标-供明细
	 */
	@Override
	public R<SupplyItemVo> getSupplyItem(String apiVersion, String orgId, String reportDate,String hrOrgTypeId) {
		List<MonitorConfigDetailDto> monitorConfigDetailDtoList=monitoringConsoleService.getDetailByOrgId(orgId,hrOrgTypeId); 
		return ok(monitoringConsoleService.getSupplyItem(orgId,reportDate,monitorConfigDetailDtoList,hrOrgTypeId));
	}

	/**
	 * 监控指标-销明细
	 */
	@Override
	public R<SaleItemVo> getSaleItem(String apiVersion, String orgId, String reportDate,String hrOrgTypeId) {
		List<MonitorConfigDetailDto> monitorConfigDetailDtoList=monitoringConsoleService.getDetailByOrgId(orgId,hrOrgTypeId); 
		return ok(monitoringConsoleService.getSaleItem(orgId,reportDate,monitorConfigDetailDtoList,hrOrgTypeId));
	}

	/**
	 * 监控指标-存明细
	 */
	@Override
	public R<StockItemVo> getStockItem(String apiVersion, String orgId, String reportDate,String hrOrgTypeId) {
		List<MonitorConfigDetailDto> monitorConfigDetailDtoList=monitoringConsoleService.getDetailByOrgId(orgId,hrOrgTypeId); 
		return ok(monitoringConsoleService.getStockItem(orgId,reportDate,monitorConfigDetailDtoList,hrOrgTypeId));
	}

	/**
	 * 监控指标-结明细
	 */
	@Override
	public R<StatementItemVo> getStatementItem(String apiVersion, String orgId, String reportDate,String hrOrgTypeId) {
		List<MonitorConfigDetailDto> monitorConfigDetailDtoList=monitoringConsoleService.getDetailByOrgId(orgId,hrOrgTypeId); 
		return ok(monitoringConsoleService.getStatementItem(orgId,reportDate,monitorConfigDetailDtoList,hrOrgTypeId));
	}
	/**
	 * 监控指标-回明细
	 */
	@Override
	public R<ReturnItemVo> getReturnItem(String apiVersion, String orgId, String reportDate, String hrOrgTypeId) {
		List<MonitorConfigDetailDto> monitorConfigDetailDtoList=monitoringConsoleService.getDetailByOrgId(orgId,hrOrgTypeId);
		return ok(monitoringConsoleService.getReturnItem(orgId,reportDate,monitorConfigDetailDtoList,hrOrgTypeId));
	}


	/**
	 * 获取监控台用户的数据权限
	 */
	@Override
	public R<UserDataPermissionVo> getMonitoringUserDataPermissions(String apiVersion, String userId) {
		return ok(monitoringConsoleService.getMonitoringUserDataPermissions(userId));
	}

	/**
	 * 业态存销比
	 */
	@Override
	public R<List<StoreSaleRateVo>> getStoreSaleRate(String apiVersion, String orgId, String reportDate) {
		return ok(monitoringConsoleService.getStoreSaleRate(orgId,reportDate));
	}
	
	/**
	 * 测试发送预警提醒
	 */
	@Override
	public R<String> warningReminderSave(String apiVersion, String reportDate) {
		return ok(monitoringConsoleService.warningReminderSave(reportDate));
	}
	
	
	@Override
	public R<String> warningReminderSend(String apiVersion, String reportDate, String dimensionCode) {
		monitoringConsoleService.warningReminderSend(reportDate,dimensionCode);
		return ok();
	}

	/**
	 * 监控台--用户的数据权限V2
	 */
	@Override
	public R<UserDataPermissionVo> getMonitoringUserDataPermissionsV2(String apiVersion, String userId) {
		return ok(monitoringUserConsoleService.getMonitoringUserDataPermissions(userId));
	}
	
	
	
	/**
	 * pc端根据待办id消除待办,  4/待办转已办 
	 */
	@Override
	public R<String> updatePcEliminateToDo(String apiVersion, String instanceId) {
		IdmUser user = getOperator();
		return ok(commonService.updatePortalProcess(instanceId, Constants.FOUR+"", user, user));
	}
	
	/**
	 * app端根据待办id消除待办,  4/待办转已办 
	 */
	@Override
	public R<String> updateAppEliminateToDo(String apiVersion, String instanceId) {
		IdmUser user = new IdmUser();
		user.setAlias(Constants.SYS);
		user.setUsercn(Constants.SYS_NAME);
		return ok(commonService.updatePortalProcess(instanceId, Constants.FOUR+"", user, user));
	}

	/**
	 * pc端根据门户待办id查看门户待办
	 * @param apiVersion
	 * @param instanceId
	 * @return
	 */
	@Override
	public R<PortalTodoVo> getPcToDo(String apiVersion, String instanceId) {
		return ok(portalTodoTaskService.getByInstanceId(instanceId));
	}

	/**
	 * app端根据门户待办id查看门户待办
	 * @param apiVersion
	 * @param instanceId
	 * @return
	 */
	@Override
	public R<PortalTodoVo> getAppToDo(String apiVersion, String instanceId) {
		return ok(portalTodoTaskService.getByInstanceId(instanceId));
	}

	/**
	 * 监控台回数据生成
	 * @param apiVersion
	 * @return
	 */
	@Override
	public R createReturn(String apiVersion, String yearMonth) {
		supervisoryConsoleReturnDetailService.createReturn(yearMonth);
		return ok();
	}
}
